<?php

use Faker\Factory as Faker;
use App\Models\GoodsAttribute;
use App\Repositories\GoodsAttributeRepository;

trait MakeGoodsAttributeTrait
{
    /**
     * Create fake instance of GoodsAttribute and save it in database
     *
     * @param array $goodsAttributeFields
     * @return GoodsAttribute
     */
    public function makeGoodsAttribute($goodsAttributeFields = [])
    {
        /** @var GoodsAttributeRepository $goodsAttributeRepo */
        $goodsAttributeRepo = App::make(GoodsAttributeRepository::class);
        $theme = $this->fakeGoodsAttributeData($goodsAttributeFields);
        return $goodsAttributeRepo->create($theme);
    }

    /**
     * Get fake instance of GoodsAttribute
     *
     * @param array $goodsAttributeFields
     * @return GoodsAttribute
     */
    public function fakeGoodsAttribute($goodsAttributeFields = [])
    {
        return new GoodsAttribute($this->fakeGoodsAttributeData($goodsAttributeFields));
    }

    /**
     * Get fake data of GoodsAttribute
     *
     * @param array $postFields
     * @return array
     */
    public function fakeGoodsAttributeData($goodsAttributeFields = [])
    {
        $fake = Faker::create();

        return array_merge([
            'goods_id' => $fake->randomDigitNotNull,
            'name' => $fake->word,
            'market_price' => $fake->word,
            'sale_price' => $fake->word,
            'sales_count' => $fake->randomDigitNotNull,
            'number' => $fake->randomDigitNotNull,
            'created_at' => $fake->word,
            'updated_at' => $fake->word
        ], $goodsAttributeFields);
    }
}
